Implementing Memoization for Partial Evaluation
نویسنده
چکیده
Memoization is a key ingredient in every partial evaluator. It enables folding by caching previously specialized functions. It is essential to make polyvariant specialization terminate. Its implementation is reasonably straightforward in a standard specializer that represents functions by closures. With the advent of handwritten program-generator generators (PGGs), implementing memoization gets harder, because PGGs use eecient standard representations of data at specialization time. We present several implementations of memoization for PGGs that are able to deal with all features of current partial evaluators, speciically partially static data and functions. The rst implementation is based on message passing. It is simple, portable, and eecient, but only suitable for untyped higher-order languages such as Scheme. The second implementation is geared towards typed language such as SML. Whereas the rst two implementations are completely portable, our third implementation exploits introspective features that may not be available in all implementations. Finally, we demonstrate that PGGs can solve the termination problem for partial evaluation. Our new incremental memoization algorithm performs incremental specialization and guarantees that specialization terminates whenever standard evaluation does. Partial evaluation is a powerful program-specialization technique based on constant propagation. Given the static (known) parameters of a source program, partial evaluation constructs a residual program|a specialized version of the program, which on application to the remaining dynamic parameters produces the same result as the original program applied to all parameters. OOine partial evaluation 10,18] consists of two phases, binding-time analysis (BTA) and static reduction. BTA transforms a program and the binding times (static/dynamic) of the parameters into an annotated program. Subsequently, the specializer applies the program to the static input, reducing static expressions and rebuilding dynamic ones.
منابع مشابه
Memoization in Type-Directed Partial Evaluation
We use a code generator—type-directed partial evaluation— to verify conversions between isomorphic types, or more precisely to verify that a composite function is the identity function at some complicated type. A typed functional language such as ML provides a natural support to express the functions and type-directed partial evaluation provides a convenient setting to obtain the normal form of...
متن کاملStaging Dynamic Programming Algorithms
Applications of dynamic programming (DP) algorithms are numerous, and include genetic engineering and operations research problems. At a high level, DP algorithms are specified as a system of recursive equations implemented using memoization. The recursive nature of these equations suggests that they can be written naturally in a functional language. However, the requirement for memoization pos...
متن کاملOptimizations of Bottom-Up Evaluation with Non-Ground Terms
Bottom-up evaluation of logic programs can be seen as an implementation of memoization. Memoization helps detect loops, avoid repeated computation when subgoals are generated repeatedly, and in conjunction with a fair search strategy, as in bottom-up evaluation, ensures that evaluation is complete. Programs that generate non-ground facts (i.e., facts containing universally quantiied variables) ...
متن کاملTabling for P-log Probabilistic Query Evaluation
We propose a new approach for implementing P-log using XASP, the interface of XSB with Smodels. By using the tabling mechanism of XSB, our system is most of the times faster than P-log. In addition, our implementation has query features not supported by P-log, as well as new set operations for domain definition.
متن کاملA Logic Your Typechecker Can Count On: Unordered Tree Types in Practice
Type systems featuring counting constraints are often studied, but seldom implemented. We describe an efficient implementation of a type system for unordered, edge-labeled trees based on Presburger arithmetic constraints. We begin with a type system for unordered trees and give a compilation into counting automata. We then describe an optimized implementation that provides the fundamental opera...
متن کامل